
var app = new Vue({
    el: '#app',
    data: {
        //搜索
        classify: [
            {id: 0,name: '无雾'},
            {id: 1,name: '轻雾'},
            {id: 2,name: '浓雾'}
        ],
        //内容
        fogFrom:{
            mid: 0,
            value: 0.0,
            url: "",
            level: 0,
            date: ""
        },
        //图片
        dialogImageUrl: '',
        dialogVisible: false
    },
    created() {
        this.addFogLevel();
    },
    methods:{
        addFogLevel(){
            this.$http.get('/admin/FogLevelToAdd',{}).then(res => {
                $("div[id*='left_y']").hide();
                $("#" + res.body.left).show();
                $("#" + res.body.show_left).attr("style", "background: #293038;");
                $("#"+res.body.top).attr("style","background: #008fbf;");
                $(".top_admin .list-group").hide();
            });
        },
        submitForm(){
            if (this.fogFrom.mid===0||this.fogFrom.level===3||this.$refs.upload.uploadFiles.length===0){
                layer.msg('请将信息完整输入!', {
                    time: 2000
                });
                return false;
            }
            let date = {
                year: new Date().getFullYear(),
                month: new Date().getMonth() < 9 ? "0" + (new Date().getMonth() + 1) : new Date().getMonth() + 1,
                date: new Date().getDate() <= 9 ? "0" + new Date().getDate() : new Date().getDate(),
            }
            this.fogFrom.date = date.year + '-' + date.month + '-' + date.date;
            this.fogFrom.url=this.$refs.upload.uploadFiles[0].raw.name;
            this.$refs.upload.submit();
        },
        //图片
        handleRemove(file) {
            this.$refs.upload.clearFiles();
            $(".el-upload--picture-card").css("display","block");
            console.log(file);
        },
        handlePictureCardPreview(file) {
            this.dialogImageUrl = file.url;
            this.dialogVisible = true;
        },
        changelist(file){
            if (this.$refs.upload){
                $(".el-upload--picture-card").css("display","none");
            }
        },
        geturl(res){
            console.log(res);
            console.log(this.fogFrom.url);
            if (this.fogFrom.mid===0||this.fogFrom.url===""||this.fogFrom.level===3){
                layer.msg('请将信息完整输入!', {
                    time: 2000
                });
                return false;
            }
            setTimeout(() => {
                this.$http.post('/admin/FogLevelAdd',this.fogFrom,{emulateJSON:true}).then(res => {
                    layer.msg('添加成功!', {
                        time: 2000
                    });
                    setTimeout(() => {
                        location.href = "/admin/fog.html";
                    }, 1000);
                });
            }, 5000);
        }
    }
})